package cn.pconline.autoclub.task;

import java.sql.SQLException;
import java.util.Date;

/**
 * 定时任务入口
 *
 * @author chensy
 */
public class App {
	
    public static void main(String[] args) {
    	//初始化Log
    	AppUtils.initLog(App.class);
    	
        if (args != null) {
            String taskName = "";
            Date d = new Date();
            if (args.length == 1) {
                taskName = args[0];
            }
            if (args.length == 2) {
                taskName = args[0];
                d = DateUtils.parseDate(args[1]);
            }
            if (taskName.equals("dailyClubMemberPetrolTask")) {
                AppUtils.log.info("run dailyClubMemberPetrolTask start...");
                ClubMemberPetrolTask t = new ClubMemberPetrolTask();
                try {
                    t.dailyClubMemberPetrolTask(d);
                } catch (SQLException ex) {
                    AppUtils.log.error("dailyClubMemberPetrolTask fail!", ex);
                }
                AppUtils.log.info("dailyClubMemberPetrolTask done!");
            } else if (taskName.equals("dailyClubPetrolTask")) {
                AppUtils.log.info("run dailyClubPetrolTask start...");
                ClubPetrolTask t = new ClubPetrolTask();
                try {
                    t.dailyClubPetrolTask(d);
                } catch (SQLException ex) {
                    AppUtils.log.error("dailyClubPetrolTask fail!", ex);
                }
                AppUtils.log.info("dailyClubPetrolTask done!");
            } else if (taskName.equals("weeklyClubPetrolTask")) {
                AppUtils.log.info("run weeklyClubPetrolTask start...");
                ClubPetrolTask t = new ClubPetrolTask();
                try {
                    t.weeklyClubPetrolTask(d);
                } catch (SQLException ex) {
                    AppUtils.log.error("weeklyClubPetrolTask fail!", ex);
                }
                AppUtils.log.info("weeklyClubPetrolTask done!");
            } else if (taskName.equals("synClubTotalPetrolTask")) {
                AppUtils.log.info("run synClubTotalPetrolTask start...");
                ClubPetrolTask t = new ClubPetrolTask();
                try {
                    t.synClubTotalPetrolTask(d);
                } catch (SQLException ex) {
                    AppUtils.log.error("synClubTotalPetrolTask fail!", ex);
                }
                AppUtils.log.info("synClubTotalPetrolTask done!");
            } else if (taskName.equals("countClubRank")) {
                AppUtils.log.info("run countClubRank start...");
                ClubPetrolTask t = new ClubPetrolTask();
                try {
                    t.countClubRank(d);
                } catch (SQLException ex) {
                    AppUtils.log.error("countClubRank fail!", ex);
                }
                AppUtils.log.info("countClubRank done!");
            } else if (taskName.equals("clubTotalMemberTask")) {
                AppUtils.log.info("run clubTotalMemberTask start...");
                ClubTotalMemberTask t = new ClubTotalMemberTask();
                try {
                    t.updateTotalMember();
                } catch (SQLException ex) {
                    AppUtils.log.error("ClubTotalMemberTask fail!", ex);
                }
                AppUtils.log.info("ClubTotalMemberTask done!");
            } else if (taskName.equals("memberRankTask")) {
                AppUtils.log.info("run memberRankTask start...");
                ClubMemberPetrolTask t = new ClubMemberPetrolTask();
                try {
                    t.memberRankTask();
                } catch (SQLException ex) {
                    AppUtils.log.error("memberRankTask fail!", ex);
                }
                AppUtils.log.info("memberRankTack done!");
            } else if (taskName.equals("initMemberAllRank")) {
                AppUtils.log.info("run initMemberAllRank start...");
                MemberRank rank = new MemberRank();
                try {
                    rank.initMemberAllRank();
                } catch (Exception e) {
                    AppUtils.log.error("initMemberAllRank fail!", e);
                }
                AppUtils.log.info("initMemberAllRank done...");
            } else if (taskName.equals("initMemberWeekRank")) {
                AppUtils.log.info("run initMemberWeekRank start...");
                MemberRank rank = new MemberRank();
                try {
                    rank.initMemberWeekRank(d);
                } catch (Exception e) {
                    AppUtils.log.error("initMemberWeekRank fail!", e);
                }
                AppUtils.log.info("initMemberWeekRank done...");
            } else if (taskName.equals("clearWeekRank")) {
                AppUtils.log.info("run clearWeekRank start...");
                MemberRank rank = new MemberRank();
                try {
                    rank.clearWeekRank();
                } catch (Exception e) {
                    AppUtils.log.error("clearWeekRank fail!", e);
                }
                AppUtils.log.info("clearWeekRank done...");
            } else {
                AppUtils.log.error("unkonw taskName");
                AppUtils.log.info("taskNameList:dailyClubMemberPetrolTask dailyClubPetrolTask"
                        + " weeklyClubPetrolTask synClubTotalPetrolTask countClubRank "
                        + "clubTotalMemberTask memberRankTask sendMessageTask");
            }
        } else {
            AppUtils.log.error("please input args: taskName [currentDate(yyyy-MM-dd HH:mm:ss)]!");
        }
    }
}
